home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / msdos / editors / eedraw / src / eep / eed-ps.c next >
Encoding:
C/C++ Source or Header  |  1992-07-29  |  5.3 KB  |  176 lines

  1. /*****************************************************************************
  2. *   Program to draw EE diagrams on postscript compatible printers.         *
  3. *                                         *
  4. * Written by:  Gershon Elber            IBM PC Ver 1.0,    Oct. 1989    *
  5. *****************************************************************************/
  6.  
  7. #include <stdio.h>
  8. #include <string.h>
  9.  
  10. #ifdef __MSDOS__
  11. #include <stdlib.h>
  12. #include <conio.h>
  13. #include <dos.h>
  14. #include <alloc.h>
  15. #include <dir.h>
  16. #endif /* __MSDOS__ */
  17.  
  18. #include "program.h"
  19. #include "config.h"
  20. #include "igraph.h"
  21. #include "eelibs.h"
  22. #include "eeredraw.h"
  23. #include "eeload.h"
  24.  
  25. /* Undef DEBUG_MALLOC_TC20 iff you have TurboC 2.0. It assumes the offset    */
  26. /* part of the pointer is always 8 which is TRUE only of TC 2.0.         */
  27. /* #define DEBUG_MALLOC_TC20  /* Add debugging aid for malloc/free routines. */
  28.  
  29. /* Clipping boundaries of current page size (A4 by default). */
  30. int EEPageSizeX = PAGE_A4_XSIZE * PAGE_SCALER / 2,
  31.     EEPageSizeY = PAGE_A4_YSIZE * PAGE_SCALER / 2;
  32. char *EEPSFontName = "Times-Roman";
  33. char *EEDataFileName = NULL;
  34. DrawGenericStruct *EEDrawList = NULL;         /* All objects are saved here. */
  35.  
  36. #ifdef __MSDOS__
  37. static char *VersionStr =
  38.     "EED-PS    IBMPC "
  39.     EEDRAW_VERSION
  40.     "    Gershon Elber,  "
  41.     __DATE__ ",   " __TIME__ "\n"
  42.     "(C) Copyright 1989 Gershon Elber, Non commercial use only.\n";
  43. #else
  44. static char *VersionStr =
  45.     "EED-PS    Unix version 1.2    Gershon Elber,  \n\
  46.     (C) Copyright 1990 Gershon Elber, Non commercial use only.\n";
  47. #endif /* __MSDOS__ */
  48.  
  49. static char *UsageStr = "Usage: EED-PS [-f FontName] [-z] EEDrawFile.EED\n";
  50. static char *LoadLibraryList = NULL;
  51. static ConfigStruct SetUp[] =
  52. {
  53.     { "Libraries",    (VoidPtr) &LoadLibraryList,    SU_STRING_TYPE },
  54.     { "FontName",    (VoidPtr) &EEPSFontName,    SU_STRING_TYPE }
  55. };
  56. #define NUM_SET_UP    (sizeof(SetUp) / sizeof(ConfigStruct))
  57.  
  58. #ifdef __MSDOS__
  59. extern unsigned int _stklen = 32766;         /* Increase default stack size. */
  60. #endif /* __MSDOS__ */
  61.  
  62. /*****************************************************************************
  63. * Main routine - Read Parameter    line and do what you need...             *
  64. *****************************************************************************/
  65. void main(int argc, char **argv)
  66. {
  67.     int i = 1;
  68.     char FullName[LINE_LEN_SHORT];
  69.     FILE *f;
  70.  
  71.     Config("eed-ps", SetUp, NUM_SET_UP);     /* Read config. file if exists. */
  72.  
  73.     while (i < argc) {
  74.     if (strcmp(argv[i], "-z") == 0) {
  75.         fprintf(stderr, "%s%s", UsageStr, VersionStr);
  76.         MyExit(-1);
  77.     }
  78.     else if (strcmp(argv[i], "-f") == 0) {
  79.         EEPSFontName = strdup(argv[++i]);
  80.     }
  81.     else if (i + 1 != argc || argv[i][0] == '-')
  82.         FatalError(UsageStr);
  83.  
  84.     i++;
  85.     }
  86.  
  87.     if (argv[i - 1][0] == '-' || argc == 1) {
  88.     fprintf(stderr, UsageStr);
  89.     FatalError("No EED file specified.\n");
  90.     }
  91.  
  92.     EEDataFileName = strdup(argv[i - 1]);
  93.  
  94.     if ((f = fopen(argv[i - 1], "rt")) == NULL) {
  95.     strcpy(FullName, argv[i - 1]);
  96.     strcat(FullName, FILE_EXTENSION);
  97.     if ((f = fopen(FullName, "rt")) == NULL) {
  98.         fprintf(stderr, UsageStr);
  99.         FatalError("Failed to open EED file");
  100.     }
  101.     }
  102.  
  103.  
  104.     IGInitGraph();                 /* Initiate the graphic driver. */
  105.  
  106.     if (LoadLibraryList != NULL) {
  107.     LoadLibraries(LoadLibraryList);
  108.     free(LoadLibraryList);
  109.     LoadLibraryList = NULL;
  110.     }
  111.  
  112.     LoadEEFile(f);
  113.     fclose(f);
  114.     RedrawAllScreen();
  115.  
  116.     MyExit(0);
  117. }
  118.  
  119. /*****************************************************************************
  120. * My Routine to    allocate dynamic memory. All program requests must call this *
  121. * routine (no direct call to malloc). Dies if no memory.             *
  122. *****************************************************************************/
  123. VoidPtr MyMalloc(unsigned size)
  124. {
  125.     VoidPtr p;
  126.  
  127.     p = malloc(size);
  128.     if (p == NULL)
  129.     FatalError("Not enough memory, exit\n");
  130.  
  131. #ifdef DEBUG_MALLOC_TC20
  132.     if (FP_OFF(p) != 8)
  133.     FatalError("Bogus pointer detected. This should be reported.\n");
  134. #endif /* DEBUG_MALLOC_TC20 */
  135.  
  136.     return p;
  137. }
  138.  
  139. /*****************************************************************************
  140. * My Routine to    free dynamic memory. All program requests must call this     *
  141. * routine (no direct call free).                         *
  142. *****************************************************************************/
  143. void MyFree(VoidPtr p)
  144. {
  145. #ifdef DEBUG_MALLOC_TC20
  146.     if (FP_OFF(p) != 8)
  147.     FatalError("Bogus pointer detected. This should be reported.\n");
  148. #endif /* DEBUG_MALLOC_TC20 */
  149.  
  150.     free(p);
  151. }
  152.  
  153. /*****************************************************************************
  154. * MyExit routine. Note it might call to CloseGraph without calling         *
  155. * InitGraph(), or call MouseClose() without MouseInit() etc. and it is the   *
  156. * responsibility of the individual modules to do nothing in these cases.     *
  157. *****************************************************************************/
  158. void MyExit(int ExitCode)
  159. {
  160.     IGCloseGraph();                /* Close the graphic driver. */
  161.  
  162.     exit(ExitCode);
  163. }
  164.  
  165. /*****************************************************************************
  166. * Same as MyExit routine, but print error message to stderr.             *
  167. *****************************************************************************/
  168. void FatalError(char *ErrMsg)
  169. {
  170.     IGCloseGraph();                /* Close the graphic driver. */
  171.  
  172.     fprintf(stderr, "EEDRAW: %s\n", ErrMsg);
  173.  
  174.     exit('F');
  175. }
  176.